package org.example.com.zwh.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.example.com.zwh.entity.Order;

import java.io.Serializable;
import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    //查询方法
    @Select("select * from t_order where id = #{id}")
    Order selectById(Serializable id);
    //根据用户查询订单
    @Select("select * from t_order where user_id = #{userId}")
    List<Order> selectByUserId(String userId);

    //增加订单
    @Insert("insert into t_order(order_id, user_id, product_id, status) values( #{orderId},#{userId}, #{productId}, #{status})")
    int insert(Order order);

    @Select("select stock from t_product where id = #{productId}")
    @Results(id = "orderResultMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "orderId", column = "order_id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "productId", column = "product_id"),
            @Result(property = "status", column = "status"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time")
    })
    int getStock(String productId);
}
